
const { ccclass, property } = cc._decorator;

@ccclass
export default class AddJoint extends cc.Component {

    static Car: cc.Node = null

    static contactCar(car: cc.Node): number {
        // console.log('contactCar')
        this.Car = car
        return this.Car.children.length - 1
    }

    static contactPreJoin(preWeldJoint: cc.WeldJoint, curWeldJoint: cc.RigidBody) {
        preWeldJoint.connectedBody = curWeldJoint
    }

    static calcAngle(pre: cc.Node, next: cc.Node) {
        let ang1 = pre.angle
        let ang2 = next.angle
        let norVec1 = cc.v2(1, 0)
        let norvec2 = cc.v2(1, 0)
        let radian1 = cc.misc.degreesToRadians(ang1)
        let radian2 = cc.misc.degreesToRadians(ang2)
        let v1 = norVec1.rotate(radian1)
        let v2 = norvec2.rotate(radian2)

        let offRadian = v1.signAngle(v2)
        let offAngle = -cc.misc.radiansToDegrees(offRadian)

        return offAngle
    }
    static addDistanceJoint(preNode,lineItem){
        preNode.getComponent(cc.DistanceJoint).connectedBody = lineItem.getComponent(cc.RigidBody)
        preNode.getComponent(cc.DistanceJoint).distance =  preNode.position.sub(lineItem.position).mag();
        preNode.getComponent(cc.DistanceJoint).frequency = 0
    }
}